package com.lxh.lxhcrm.model.pojos;

import javax.persistence.*;
import java.util.List;
import java.util.Objects;

/**
 * 商品详情
 */
@Entity
@Table(name = "pro_detail", schema = "lxh_crm", catalog = "")
public class  ProDetail {
    private int proDetailId;
    private Double proPrice;
    private int proOn;
    private int proNum;
    private String proImgSrc;               // 商品图片
    private int wareNum;

    private Product product;                // 产品
    private List<Ability> abilities;        // 属性值
    private List<AbiCen> abiCens;

    @OneToMany(mappedBy = "proDetail")
    public List<AbiCen> getAbiCens() {
        return abiCens;
    }

    public void setAbiCens(List<AbiCen> abiCens) {
        this.abiCens = abiCens;
    }

    @Basic
    @Column(name = "pro_img_src", nullable = true, length = 0)
    public String getProImgSrc() {
        return proImgSrc;
    }

    public void setProImgSrc(String proImgSrc) {
        this.proImgSrc = proImgSrc;
    }

    @ManyToMany
    @JoinTable(
            name = "abi_cen",
            joinColumns = {@JoinColumn(name = "pro_detail_id")},
            inverseJoinColumns = {@JoinColumn(name = "ability_id")}
    )
    public List<Ability> getAbilities() {
        return abilities;
    }

    public void setAbilities(List<Ability> abilities) {
        this.abilities = abilities;
    }

    @Basic
    @Column(name = "pro_num", nullable = true, precision = 0)
    public int getProNum() {
        return proNum;
    }

    public void setProNum(int proNum) {
        this.proNum = proNum;
    }

    @Basic
    @Column(name = "ware_num", nullable = true, precision = 0)
    public int getWareNum() {
        return wareNum;
    }

    public void setWareNum(int wareNum) {
        this.wareNum = wareNum;
    }

    @ManyToOne
    @JoinColumn(name = "product_id")
    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    @Basic
    @Column(name = "pro_on", nullable = true, precision = 0)
    public int getProOn() {
        return proOn;
    }

    public void setProOn(int proOn) {
        this.proOn = proOn;
    }

    @Id
    @Column(name = "pro_detail_id", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public int getProDetailId() {
        return proDetailId;
    }

    public void setProDetailId(int proDetailId) {
        this.proDetailId = proDetailId;
    }

    @Basic
    @Column(name = "pro_price", nullable = true, precision = 0)
    public Double getProPrice() {
        return proPrice;
    }

    public void setProPrice(Double proPrice) {
        this.proPrice = proPrice;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ProDetail detail = (ProDetail) o;
        return proDetailId == detail.proDetailId &&
                proOn == detail.proOn &&
                proNum == detail.proNum &&
                wareNum == detail.wareNum &&
                Objects.equals(proPrice, detail.proPrice) &&
                Objects.equals(proImgSrc, detail.proImgSrc) &&
                Objects.equals(product, detail.product) &&
                Objects.equals(abilities, detail.abilities) &&
                Objects.equals(abiCens, detail.abiCens);
    }

    @Override
    public int hashCode() {
        return Objects.hash(proDetailId, proPrice, proOn, proNum, proImgSrc, wareNum, product, abilities, abiCens);
    }
}
